package com.example.studentgrades.controller;

import com.example.studentgrades.entity.Course;
import com.example.studentgrades.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courses")
public class CourseController {
    @Autowired
    private CourseService courseService;

    @GetMapping("/listAll")
    public ResponseEntity<List<Course>> listAllCourses() {
        List<Course> courses = courseService.findAll();
        return ResponseEntity.ok(courses);
    }

    @GetMapping("/getById/{courseId}")
    public ResponseEntity<Course> getCourseById(@PathVariable Integer courseId) {
        Course course = courseService.findById(courseId);
        return ResponseEntity.ok(course);
    }

    @PostMapping("/add")
    public ResponseEntity<Void> addCourse(@RequestBody Course course) {
        courseService.save(course);
        return ResponseEntity.ok().build();
    }
}
